<?php
/**
* change room status : roomstatus.php
*/
session_start();
include_once("config/config.inc.php");
$room = ($_POST["roomid"]) ? $_POST["roomid"] : 0;
$status = ($_POST["status_id"]) ? $_POST["status_id"] : 0;
$reason = ($_POST["newremarks"]) ? $_POST["newremarks"] : '';
$user = $_SESSION["hotel"]["userid"];

if($room && $status ) {
	$statusid= getId($status);
	$now = date("Y-m-d H:i:s");
	$sql = "insert into room_log values (null, '$room','$status','$now','$user','$reason') ";
	mysql_query($sql) or die('{success:false,error:"Unable to log room status."}');
	$sql = "update rooms set status='$status', last_update='$now', update_by='$user' where room_id='$room' ";
	mysql_query($sql) or die('{success:false,error:"Unable to update room status.$sql"}');
	echo '{success:true}';
}else{
	echo '{success:false,error:"Invalid Room or Status flags."}';
}

function getId($text) {
	$thisarr = array('','Available','Occupied','Cleaning','Maintenance');
	for($x=0;$x < count($thisarr);$x++) {
		if($thisarr[$x]==$text) return $x;
	}
}
?>